#include <math.h>

#include "defs.h"
#include "player.h"
#include "map.h"

player_t player = {
  100, // initial position
  100, // todo: add to map file
  1,
  1,
  0,
  0,
  (float)M_PI_2,
  200,
  145 * (M_PI / 180)
};

void movePlayer(float deltaTime){
  float moveStep, newPlayerX, newPlayerY;
  player.rotationAngle += player.turnDirection * player.turnSpeed * deltaTime;
  moveStep = (float)player.walkDirection * player.walkSpeed * deltaTime;
  newPlayerX = player.x + cos(player.rotationAngle) * moveStep;
  newPlayerY = player.y + sin(player.rotationAngle) * moveStep;
  
  if(!mapHasWallAt(newPlayerX,newPlayerY)) {
    player.x = newPlayerX;
    player.y = newPlayerY;
  }
}

void renderPlayer() {
  /* SDL_Rect playerRect; */

  /* SDL_SetRenderDrawColor(renderer, 255, 255, 2
55, 255); */
  /* playerRect.x = (int)(player.x * MINIMAP_SCALE_FACTOR); */
  /* playerRect.y = (int)(player.y * MINIMAP_SCALE_FACTOR); */
  /* playerRect.h = (int)(player.width * MINIMAP_SCALE_FACTOR); */
  /* playerRect.w = (int)(player.height * MINIMAP_SCALE_FACTOR); */

  /* SDL_RenderFillRect(renderer, &playerRect); */
  /* SDL_RenderDrawLine(renderer, */
  /*                    (int)(player.x * MINIMAP_SCALE_FACTOR), */
  /*                    (int)(player.y * MINIMAP_SCALE_FACTOR), */
  /*                    (int)((player.x + cos(player.rotationAngle) * 40) * MINIMAP_SCALE_FACTOR), */
  /*                    (int)((player.y + sin(player.rotationAngle) * 40) * MINIMAP_SCALE_FACTOR)); */
}
